<template>
  <a-popconfirm trigger="click" placement="right" :disabled="disabled" @confirm="ok">
    <template slot="title">
      <p>修改预算</p>
      <a-radio-group v-model="type" button-style="solid">
        <a-radio-button :value="1" :disabled="disabledBtn1">
          不限
        </a-radio-button>
        <a-radio-button :value="2">
          自定义
        </a-radio-button>
      </a-radio-group>
      <div v-show="type == 2" style="margin-top: 12px;">
        <a-input-number id="inputNumber" v-model="cbudget" :min="50" :max="9999999.99" style="width: 120px" /> 元
      </div>
    </template>
    <slot />
  </a-popconfirm>
</template>


<script>
import {updateCampaignBudget} from '@/api/dianshang/dianshang'

export default {
  // 修改 shujiList 预算
  name:'BudgetView',
  props:{
    bidType:{
      type: [Number, String]
    },
    campaignId:[String, Number],
    userName: [String],
    budget: [String, Number]
  },
  data() {
    return {
      type: 1,
      disabled:false,
      disabledBtn1: false,
      cbudget: 50,
    }
  },
  created(){
    this.setType()
  },
  methods:{
    ok(){
      if(this.type == 1){
        this.cbudget = 0
      }
      let params = {
        budget: this.cbudget,
        campaignId: this.campaignId,
        userName: this.userName
      }
      const hide = this.$message.loading('修改中')
      updateCampaignBudget(params).then((res) => {
        hide()
        if(res.errcode == 0){
          this.$message.success('修改成功')
          this.$emit('change')
        }
      }).catch(() => {
        hide()
      });
    },
    setType(){
      // 根据出价模式设置type,放量没有不限
      if(this.bidType != 1 && this.bidType != 4){
        // this.disabled = true
      }else if(this.bidType == 4){
        this.type = 2
        this.cbudget = this.budget
        this.disabledBtn1 = true
      }
    },
  }
}
</script>
